
<template>
	<!-- 添加弹框 -->
	<el-dialog  title=""  visible :show-close="false" :modal-append-to-body="false" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;"></i>
	    <div class="bt">课程添加</div>
		<div class="input-block" style="margin-top: 20px;">
			<span>课程名称</span>
			<el-input v-model="vkcmc" placeholder="请输入课程名称" icon="add"  class="input"></el-input>
		    <!--<el-button size="small" @click="showwp()" class="select-block2" >选择</el-button>-->
		</div>
		<div class="input-block">
			<span>课时</span>
			<el-input v-model="vks" placeholder="请输入课时" icon="add" class="input"></el-input>
		</div>
		<div class="input-block">
			<span>课时单价</span>
			<el-input v-model="vjcjg" placeholder="请输入基础价格" icon="add" class="input"></el-input>
		</div>
		<div class="input-block">
			<span>总价</span>
			<el-input v-model="jg" placeholder="请输入价格" icon="add" class="input"></el-input>
		</div>
		<div class="input-block">
			<span>是否启用</span>
      <el-select v-model="vsfjs" class="input" >
          <el-option label="启用" value="Y"></el-option>
          <el-option label="禁用" value="N"></el-option>
      </el-select>
		</div>
		<Kschoose class="wpfl" @wpchoose="wpchooseed" @close="wpchoosecancel" v-if="showchoselist"></Kschoose>


		<el-button type="primary" class="submit" @click="submit">保存</el-button>
	</el-dialog>
</template>
<script type="text/javascript">
	import Kschoose from '../../manage/kssz/kschoose'
	import qs from 'qs'
	export default {
		components: { Kschoose},
		data() {
			return {
				showchoselist: false,
				vfxkcidmc:'',
//				jg: '',
				vjcjg: '',
				vks: '',
				vkcmc: '',
				vsfjs: 'Y',
				dialogTableVisible: true
			}
		},
		methods: {
			submit() {
				//检测
				this.$store.state.loading = true;
			   if(!this.vjg) {
					this.$message.warning('请填写课程名称');
					this.$store.state.loading = false;
					return;
				}
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					jg: this.vjg,
					jcjg: this.vjcjg,
					ks: this.vks,
					kcmc: this.vkcmc,
					sfjs: this.vsfjs,
					yhid: logininfo.id,
					xxid:logininfo.xxid
				});
				//执行
				this.axios.post(this.$store.state.api + 'fxkc/insert', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'add', cancel: false });
							this.$store.state.loading = false;
						} else {
							this.$emit('close', { type: 'add', cancel: false });
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.warning("服务器繁忙，请重试");
						//this.$emit('close', { type: 'add', cancel: false });
						this.$store.state.loading = false;
					})
			},
			showwp() {
				this.showchoselist = true;
			},
			wpchooseed(josndata) {
				console.log(josndata,'wzwZ');
//				this.vfxkcidmc = josndata.kcmc;
				this.vfxkcid = josndata.fxkcid;
				this.vkssl=josndata.kssl;

				this.showchoselist = false;
			},
			wpchoosecancel(setting) {
				// console.log()
				if(setting.cancel == false){
					this.vfxkcid = setting.data[0].id;
//					this.vfxkcidmc = setting.data[0].mc;
					this.vjcidmc = setting.data[0].cmc;
					this.vjcid = setting.data[0].jcid;
					this.vcid = setting.data[0].cid;
					this.vkssl = setting.data[0].number;
				}
				this.showchoselist = false;
			},
			cancel() {
				this.$emit('close', { type: 'add', cancel: true })
			}
		},
		computed: {
		          jg(){
		            let number = this.vjcjg * this.vks;
		            if (number<=0) {
		              return 0.00
		            }
		          	return number;
		          },
        	 }
	}
</script>
<style lang="less" scoped>
	.wrap {
		.input-block {
			margin-bottom: 20px;
			text-align: center;
		}
		.bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top: 0;
			left: 0;
			// margin-top: -70px;
			background: #50BFFF;
			// margin-left: -20px;
			// margin-bottom: 20px;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
		.close{
				z-index: 10;
				position: absolute;
		}
		.input {
			width: 300px;
			display: inline-block;
		}
		.input-block span {
			display: inline-block;
			width: 70px;
			text-align: right;
		}
		.submit {
			width: 120px;
			display: block;
			margin: 0 auto;
			margin-top: 20px;
		}
	}
</style>
